﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LeetCode.StringOperation
{
    public class ReverseString
    {
        private static char[] Demo = { 'h', 'e', 'l', 'l', 'o' };


        public static void Run()
        {
            Method3();
            foreach (var item in Demo)
            {
                Console.Write(item + "  ");
            }
        }
        
        /// <summary>
        /// Reverse方法
        /// </summary>
        public static void Method1()
        {
            //该方法需重新对变量赋值，且需要进行相关转换
            //Demo = (Demo.Reverse()).ToArray<char>();

            //该方法无需重新对变量赋值
            //Array.Reverse(Demo);

            Demo = Demo.Reverse().ToArray();
        }

        /// <summary>
        /// 通过List中Reverse方法
        /// </summary>
        public static void Method2()
        {
            List<char> _List = Demo.ToList();
            _List.Reverse();
            foreach (var item in _List)
            {
                Console.Write(item + "  ");
            }

            Console.WriteLine();
            Demo = _List.ToArray();
            foreach (var item in Demo)
            {
                Console.Write(item + "  ");
            }
        }

        /// <summary>
        /// 利用临时数组
        /// </summary>
        public static void Method3()
        {
            char[] _Temp = new char[Demo.Length];
            for (int i = 0; i < Demo.Length; i++)
            {
                _Temp[i] = Demo[Demo.Length - i - 1];
            }
            for (int i = 0; i < Demo.Length; i++)
            {
                Demo[i] = _Temp[i];
            }
        }
    }
}
